package info.niwota.ezb;

import java.io.FileInputStream;
import java.io.InputStream;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;

/**
 * @author qiangli
 * 
 */
public class ViewImageActivity extends Activity {

	private ImageView imageView;

	@Override
	public void onCreate(Bundle icicle) {
		super.onCreate(icicle);
		setContentView(R.layout.viewimage);
		imageView = ((ImageView) findViewById(R.id.image));
		Uri uri = getIntent().getData();
		if (uri == null) {
			finish();
		}
		//
		InputStream is = null;
		try {
			if ("file".equals(uri.getScheme())) {
				is = new FileInputStream(uri.getPath());
				Drawable d = Drawable.createFromStream(is, "src");
				imageView.setImageDrawable(d);
			} else {
				imageView.setImageURI(uri);
			}
		} catch (Exception e) {
			e.printStackTrace();
			//
			finish();
		} finally {
			Util.closeSilently(is);
		}
	}
}
